package StudyCode.summary.mycollection;

import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class LoopThroughListReversely {
	public static void main(String[] args) {
		String[] colors = {"black", "yellow", "green", "blue", "violet", "silver"};
		List<String> list1 = new LinkedList<>();

		for (String color : colors) {
			list1.add(color);
		}
		printList(list1);
		printReversedList(list1);
	}

	private static void printList(List<String> list) {
		System.out.printf("%nlist:%n");

		for (String color : list)
			System.out.printf("%s ", color);

		System.out.println();
	}

	private static void printReversedList(List<String> list) {
		ListIterator<String> iterator = list.listIterator(list.size());

		System.out.printf("%n反向 List:%n");

		while (iterator.hasPrevious())
			System.out.printf("%s ", iterator.previous());
	}
}
